package com.wxapp.common.core.mybatis.mysql;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.wxapp.common.constant.enums.SqlMethodEnum;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * @author lgl
 * @Description 判断是否存在
 * @Datetime 2023/4/24 9:07
 * @Modified By
 */
public class IsExist extends AbstractMethod {
    private SqlMethodEnum sqlMethod;
    public IsExist(SqlMethodEnum sqlMethod) {
        super(sqlMethod.getMethod());
        this.sqlMethod=sqlMethod;
    }
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        var format = String.format(sqlMethod.getSql(), sqlFirst(), tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo));
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, format, modelClass);
        return this.addSelectMappedStatementForOther(mapperClass, sqlSource, boolean.class);
    }
}
